﻿using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using BUS;
using DTO;

namespace QuanLyHocSinh.GUI
{
    public partial class F_TraCuuHocSinh : DevExpress.XtraEditors.XtraUserControl
    {
        public F_TraCuuHocSinh()
        {
            InitializeComponent();
        }

        private void F_TraCuuHocSinh_Load(object sender, EventArgs e)
        {
            try
            {
                DataTable dulieulookup = new DataTable();
                dulieulookup = BUSTraCuuHocSinh.LietKeKhoiLop();
                this.lkKhoiLop.Properties.DataSource = dulieulookup;
                this.lkKhoiLop.Properties.DisplayMember = "TENKHOILOP";
                this.lkKhoiLop.Properties.ValueMember = "MAKHOILOP";
                this.lkKhoiLop.Properties.ShowHeader = false;
                this.lkKhoiLop.Properties.ShowFooter = false;
                this.lkKhoiLop.Properties.ImmediatePopup = false;
                this.lkKhoiLop.Properties.SearchMode = SearchMode.AutoComplete;
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void lkKhoiLop_EditValueChanged(object sender, EventArgs e)
        {
            try
            {
                DataTable dulieulookup = new DataTable();
                dulieulookup = BUSTraCuuHocSinh.LietKeLop(lkKhoiLop.EditValue);
                this.lkTenLop.Properties.DataSource = dulieulookup;
                this.lkTenLop.Properties.DisplayMember = "TENLOP";
                this.lkTenLop.Properties.ValueMember = "MALOP";
                this.lkTenLop.Properties.ShowHeader = false;
                this.lkTenLop.Properties.ShowFooter = false;
                this.lkTenLop.Properties.ImmediatePopup = false;
                this.lkTenLop.Properties.SearchMode = SearchMode.AutoComplete;
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnThucHien_Click(object sender, EventArgs e)
        {
            try
            {
                if (lkKhoiLop.EditValue != null || this.txtHovaTen.Text.Trim() != "")
                {
                    this.dgvBangDiemTrungBinh.DataSource = BUSTraCuuHocSinh.BangDiemHocSinh(lkKhoiLop.EditValue, lkTenLop.EditValue, txtHovaTen.Text);
                    this.dgvThongTinHocSinh.DataSource = BUSTraCuuHocSinh.DanhSachHocSinh(lkKhoiLop.EditValue, lkTenLop.EditValue, txtHovaTen.Text);
                    if (gvThongTinHocSinh.RowCount < 1)
                    {
                        XtraMessageBox.Show("Không Tìm Thấy Thông Tin Theo Nội Dung Tìm Kiếm!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }   
                else
                {
                    XtraMessageBox.Show("Vui Lòng Ít Nhất 1 Thông Tin Để Thực Hiện!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void btnLamLai_Click(object sender, EventArgs e)
        {
            this.lkKhoiLop.EditValue = null;
            this.lkTenLop.EditValue = null;
            this.txtHovaTen.Text = null;
            this.dgvThongTinHocSinh.DataSource = this.dgvBangDiemTrungBinh.DataSource = null;
        }
    }
}
